package com.nanhai.buddhist.college.module.study.service.teacherevaluation;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.nanhai.buddhist.college.module.study.controller.admin.teacherevaluation.vo.*;
import com.nanhai.buddhist.college.module.study.dal.dataobject.teacherevaluation.TeacherEvaluationDO;
import com.nanhai.buddhist.college.framework.common.util.collection.CollectionUtils;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;

import com.nanhai.buddhist.college.module.study.convert.teacherevaluation.TeacherEvaluationConvert;
import com.nanhai.buddhist.college.module.study.dal.mysql.teacherevaluation.TeacherEvaluationMapper;

import static com.nanhai.buddhist.college.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.nanhai.buddhist.college.module.study.enums.ErrorCodeConstants.*;

/**
 * 教师评价 Service 实现类
 *
 * @author 南海佛学院
 */
@Service
@Validated
public class TeacherEvaluationServiceImpl implements TeacherEvaluationService {

    @Resource
    private TeacherEvaluationMapper teacherEvaluationMapper;

    @Override
    public String createTeacherEvaluation(TeacherEvaluationCreateReqVO createReqVO) {
        // 插入
        TeacherEvaluationDO teacherEvaluation = TeacherEvaluationConvert.INSTANCE.convert(createReqVO);
        teacherEvaluationMapper.insert(teacherEvaluation);
        // 返回
        return teacherEvaluation.getId();
    }

    @Override
    public void updateTeacherEvaluation(TeacherEvaluationUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateTeacherEvaluationExists(updateReqVO.getId());
        // 更新
        TeacherEvaluationDO updateObj = TeacherEvaluationConvert.INSTANCE.convert(updateReqVO);
        teacherEvaluationMapper.updateById(updateObj);
    }

    @Override
    public void deleteTeacherEvaluation(String id) {
        // 校验存在
        this.validateTeacherEvaluationExists(id);
        // 删除
        teacherEvaluationMapper.deleteById(id);
    }

    private void validateTeacherEvaluationExists(String id) {
        if (teacherEvaluationMapper.selectById(id) == null) {
            throw exception(TEACHER_EVALUATION_NOT_EXISTS);
        }
    }

    @Override
    public TeacherEvaluationDO getTeacherEvaluation(String id) {
        return teacherEvaluationMapper.selectById(id);
    }

    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationList(Collection<String> ids) {
        return CollectionUtils.isEmpty(ids) ? Collections.emptyList() : teacherEvaluationMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<TeacherEvaluationDO> getTeacherEvaluationPage(TeacherEvaluationPageReqVO pageReqVO) {
        return teacherEvaluationMapper.selectPage(pageReqVO);
    }

    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationList(TeacherEvaluationExportReqVO exportReqVO) {
        return teacherEvaluationMapper.selectList("id",exportReqVO);
    }



    /**
    * 获得教师评价列表, 根据 studentId 查询
    *
    * @param  studentId  学生id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListBystudentId(String studentId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getStudentId,studentId);
    }

    /**
    * 获得教师评价列表, 根据 teacherId 查询
    *
    * @param  teacherId  老师id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByteacherId(String teacherId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getTeacherId,teacherId);
    }

    /**
    * 获得教师评价列表, 根据 collegeId 查询
    *
    * @param  collegeId  所属学院id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListBycollegeId(String collegeId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getCollegeId,collegeId);
    }

    /**
    * 获得教师评价列表, 根据 departmentId 查询
    *
    * @param  departmentId  所属系部id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListBydepartmentId(String departmentId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getDepartmentId,departmentId);
    }

    /**
    * 获得教师评价列表, 根据 professionsId 查询
    *
    * @param  professionsId  所属专业id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByprofessionsId(String professionsId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getProfessionsId,professionsId);
    }

    /**
    * 获得教师评价列表, 根据 classeId 查询
    *
    * @param  classeId  所属班级id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByclasseId(String classeId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getClasseId,classeId);
    }

    /**
    * 获得教师评价列表, 根据 evaluationItemId 查询
    *
    * @param  evaluationItemId  评价项目id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByevaluationItemId(String evaluationItemId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getEvaluationItemId,evaluationItemId);
    }

    /**
    * 获得教师评价列表, 根据 scoreItemId 查询
    *
    * @param  scoreItemId  评分等级id 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByscoreItemId(String scoreItemId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getScoreItemId,scoreItemId);
    }

    /**
    * 获得教师评价列表, 根据 orgId 查询
    *
    * @param  orgId  机构编号 查询条件
    * @return 教师评价列表
    */
    @Override
    public List<TeacherEvaluationDO> getTeacherEvaluationListByorgId(Integer orgId){
        return teacherEvaluationMapper.selectList(TeacherEvaluationDO::getOrgId,orgId);
    }


    /**
     * 获取教师评价表的所有学院
     * @return
     */
    @Override
    public List<TeacherEvaluationDO> selectAllCollegesList() {
        return teacherEvaluationMapper.selectAllCollegesList();
    }

    /**
     * 获得教师评价表的所有班级
     * @return
     */
    @Override
    public List<TeacherEvaluationDO> selectAllClassesList() {
        return teacherEvaluationMapper.selectAllClassesList();
    }
}
